<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="测站名称" prop="statNm">
        <el-input
          v-model="queryParams.statNm"
          placeholder="请输入测站名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备号" prop="devNo">
        <el-input
          v-model="queryParams.devNo"
          placeholder="请输入设备号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在断面" prop="crossCd">
        <el-select v-model="queryParams.crossCd" placeholder="请选择断面" clearable filterable >
          <el-option
            v-for="dict in dmdata"
            :key="dict.crossCd"
            :label="dict.crossNm"
            :value="dict.crossCd"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="测站类型" prop="statType">
        <el-select
          v-model="queryParams.statType"
          placeholder="请选择测站类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.stat_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="监测方式" prop="statMode">
        <el-select
          v-model="queryParams.statMode"
          placeholder="请选择监测方式"
          clearable
        >
          <el-option
            v-for="dict in dict.type.stat_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="建设属性" prop="statId">
        <el-select v-model="queryParams.statId" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.stat_id"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="测站状态" prop="delFlag">
        <el-select v-model="queryParams.delFlag" placeholder="请选择" clearable>
          <el-option
            v-for="dict in dict.type.stat_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['datam:StStationB:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['datam:StStationB:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['datam:StStationB:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['datam:StStationB:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="StStationBList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="测站名称"
        align="left"
        prop="statNm"
        width="300"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column label="所在断面" :show-overflow-tooltip="true"  align="left" prop="crossNm">
      </el-table-column>
      <el-table-column label="测站类型" align="left" prop="statType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.stat_type"
            :value="scope.row.statType"
          />
        </template>
      </el-table-column>
      <el-table-column label="监测方式" align="center" prop="statMode">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.stat_mode"
            :value="scope.row.statMode"
          />
        </template>
      </el-table-column>
      <el-table-column label="监测频次(分钟)" align="center" prop="statFreq">
      </el-table-column>
      <!--<el-table-column label="测站方位" align="center" prop="statPos">-->

      <!--</el-table-column>-->
      <el-table-column label="对应设备号" :show-overflow-tooltip="true"  align="left" prop="devNo">
      </el-table-column>
            <el-table-column
        label="建设属性"
        :show-overflow-tooltip="true"
        align="left"
        prop="statId"
      >
      </el-table-column>
      <el-table-column label="测站状态">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.stat_status"
            :value="scope.row.delFlag"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['datam:StStationB:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['datam:StStationB:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改测站信息登记对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" class="czxx" >
        <el-row>
          <el-col :span="12">
            <el-form-item label="测站名称" prop="statNm">
              <el-input v-model="form.statNm" placeholder="请输入测站名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所在断面"  prop="crossCd">
              <el-select v-model="form.crossCd" placeholder="请选择断面" clearable filterable>
                <el-option
                  v-for="dict in dmdata"
                  :key="dict.crossCd"
                  :label="dict.crossNm"
                  :value="dict.crossCd"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测站类型" prop="statType">
              <el-select v-model="form.statType" placeholder="请选择测站类型">
                <el-option
                  v-for="dict in dict.type.stat_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="监测方式" prop="statMode">
              <el-select v-model="form.statMode" placeholder="请选择监测方式">
                <el-option
                  v-for="dict in dict.type.stat_mode"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测站频次" prop="statFreq">
              <el-input v-model="form.statFreq" placeholder="请输入测站频次" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="测站方位" prop="statPos">
              <el-input v-model="form.statPos" placeholder="请输入测站方位" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="对应设备号" prop="devCd">
              <el-select v-model="form.devCd" placeholder="请选择对应设备号" clearable filterable>
                <el-option
                  v-for="dict in sbdata"
                  :key="dict.devCd"
                  :label="dict.devNo"
                  :value="dict.devCd"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建成日期" prop="statDate">
              <el-date-picker
                clearable
                v-model="form.statDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择建成日期"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="建设属性" prop="statId">
          <el-select v-model="form.statId" placeholder="请选择" clearable>
            <el-option
              v-for="dict in dict.type.stat_id"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="测站状态" prop="delFlag">
          <el-select
              v-model="form.delFlag"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="dict in dict.type.stat_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="statMark">
          <el-input v-model="form.statMark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listStStationB,
  getStStationB,
  delStStationB,
  addStStationB,
  updateStStationB,
} from "@/api/datam/StStationB";
import { allListStCrossB } from "@/api/datam/StCrossB";
//未查询全部
import { allListCmDeviceB } from "@/api/datam/CmDeviceB";

export default {
  name: "StStationB",
  dicts: ["stat_type", "stat_mode", "stat_id", "stat_status"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测站信息登记表格数据
      StStationBList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        statNm: null,
        crossCd: null,
        statType: null,
        statMode: null,
        statFreq: null,
        statPos: null,
        devCd: null,
        statDate: null,
        statMark: null,
        devNo:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      dmdata:[],
      sbdata:[]
    };
  },
  created() {
    this.getdmList();
    this.getsbList();
    this.getList();
  },
  methods: {
    /** 查询断面列表 */
    getdmList() {
      this.loading = true;
      allListStCrossB(this.queryParams).then((response) => {
        this.dmdata = response.rows;
      });
    },
    /** 查询设备列表 */
    getsbList() {
      this.loading = true;
      allListCmDeviceB(this.queryParams).then((response) => {
        this.sbdata = response.rows;
      });
    },
    /** 查询测站信息登记列表 */
    getList() {
      this.loading = true;
      listStStationB(this.queryParams).then((response) => {
        this.StStationBList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        statCd: null,
        statNm: null,
        crossCd: null,
        statType: null,
        statMode: null,
        statFreq: null,
        statPos: null,
        devCd: null,
        statDate: null,
        statMark: null,
        devNo:null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.statCd);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加测站信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const statCd = row.statCd || this.ids;
      getStStationB(statCd).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改测站信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.statCd != null) {
            updateStStationB(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStStationB(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const statCds = row.statCd || this.ids;
      this.$modal
        .confirm('是否确认删除测站信息登记编号为"' + statCds + '"的数据项？')
        .then(function () {
          return delStStationB(statCds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "datam/StStationB/export",
        {
          ...this.queryParams,
        },
        `测站信息_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-table .cell {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: break-all;
  line-height: 23px;
  padding-left: 10px;
  padding-right: 10px;
}

.czxx{
  .el-select {
    width: 100%;
  }

  .vue-treeselect{
      width: 100%;
  }

  .el-date-editor{
      width: 100%;
  }
}
</style>
